
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

local v15up = Vector(0,0,15)
function ENT:PhysicsUpdate(phys,deltatime)
	
	phys:Wake()
	deltatime = FrameTime()

	if self.Crash then
		if self:GetOwner() and self:GetOwner():IsValid() then
			self:GetOwner():DestroyVehicle(nil)
		end
	end
	
	local v = self.Driver
	if v == nil or v == NULL then phys:EnableGravity(true) return SIM_NOTHING end
	if not v:IsValid() then phys:EnableGravity(true) return SIM_NOTHING end
	
	v:SetPos(self:GetPos() + v15up)
	
	local pos = self:GetPos()
	local ang = self:GetTrueAngles()
	local curang = self:GetAngles()
	local forward = self:GetTrueForward()
	local down = Vector(0,0,-20)
	
	self.SP={}

	if v:KeyDown( IN_FORWARD ) then
	
		self:SetSoundLoop(self.DriveSounds.Drive)
		
		self.SP.secondstoarrive	= 1
		self.SP.pos			    = pos + (self.BaseSpeed * forward) 											
		self.SP.angle			= Angle(270,math.NormalizeAngle(v:EyeAngles().y + 180),0) //ang //self.StoredAngle + Angle(3,0,0)
		self.SP.maxangular		= 5000
		self.SP.maxangulardamp	= 10000
		self.SP.maxspeed		= 1400
		self.SP.maxspeeddamp	= 1500 //jesus fuck that took a long time to find
		self.SP.dampfactor		= .5
		self.SP.teleportdistance	= 5000      
		self.SP.deltatime		= deltatime
		phys:ComputeShadowControl(self.SP) //make them move!
		
	elseif ( v:KeyDown( IN_BACK ) ) then
	
		self:SetSoundLoop(self.DriveSounds.Idle)
		
		self.SP.secondstoarrive	= 1
		self.SP.pos		    	= pos + (self.BaseSpeed * forward * -1) 											
		self.SP.angle			= Angle(270,math.NormalizeAngle(v:EyeAngles().y - 180),0)
		self.SP.maxangular		= 5000
		self.SP.maxangulardamp	= 10000
		self.SP.maxspeed		= 1000000
		self.SP.maxspeeddamp	= 10000
		self.SP.dampfactor		= 0.8
		self.SP.teleportdistance	= 500         
		self.SP.deltatime		= deltatime
		phys:ComputeShadowControl(self.SP) //make them move!
		
	end
end